<template>
	<view>
		<page-head headTitle="提现" :returnButton="true" @clickLeftReturn="clickLeftReturn"></page-head>
		<view class="m-t9">
			<view>
				<view class="scan-mt bg-pic flex justify-content">
					<view>
						<view class="width flex align-center justify-content">
							<text><text class="store-size font-weight">{{money}}</text></text>
						</view>
						<view class="width flex align-center justify-content">
							<text>营业额(元)</text>
						</view>
					</view>
				</view>	
				<view class="bg-white mr-5 m-r5 p-t-b10 p-l-r withdraw-mt border-r2">
					<text class="fs-3">提现金额</text>
					<input v-model="getNumber" @input="onKeyInput" type="number" class="withraw-input p-l2 border m-t-18 border-r" placeholder-class="fs-2 input-goods" placeholder="最低提现金额1元">
				</view>
				<view class="p-l2 p-r2">
					<bright-button title="提现到微信" class="m-t-b" @licekSubmit="licekSubmit"></bright-button>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
import pageHead from '@/components/common/page-head.vue'
import brightButton from '@/components/common/bright-button.vue'
	export default {
		components:{
			pageHead,
			brightButton
		},
		data() {
			return {
				money:0,
				getNumber:''
			}
		},
		onLoad() {
			this.account();
		},
		methods: {
			clickLeftReturn(){
				const pages = getCurrentPages() ;
				if(pages.length >1) {
					uni.navigateBack({
						delta: 1
					});
				}else{
					//返回上一页失败后强制回到首页
					uni.redirectTo({
						url: '../index/index'
					})
				}
			},
			onKeyInput: function(event) {
			    this.amount = event.target.value;
				//console.log(this.amount);
				
			},
			account(){
				this.$myRequest({
					method:'POST',
					url:'/api/guide/account'
				}).then(res=>{
					console.log(res);
					if(res.data.code == 1){
						this.money = res.data.data.balance;
					}	
				})
			},
			licekSubmit(){
				var getNumber = Number(this.getNumber);
				var maxNumber = Number(this.money);
				if(getNumber < 1){
					this.showMessage('最低提现金额1元');return;
				}
				if(getNumber > maxNumber){
					this.showMessage('最多只能提现'+maxNumber+'元');return;
				}
				this.$myRequest({
					method:'POST',
					url:'/api/guide/withdrawal',
					data:{
						amount:getNumber,
					},
				}).then(res=>{
					if(res.data.code == 1){
						uni.redirectTo({
							url: '../guide-wallet/guide-wallet'
						})
					}else{
						this.showMessage(res.data.msg);return;
					}
				})
				
			},
			showMessage(title){
				uni.showToast({
				    title: title,
				    duration: 3000,
					icon:"none",
				});
			}
		}
	}
</script>

<style>
.bg-pic{height: 340rpx; background-image: url(../../../static/images/store.png);background-repeat:no-repeat;background-size:100% 100%;-moz-background-size:100% 100%;}
.scan-money{width: 428rpx;}
.store-size{font-size: 70rpx;}
.withdraw-mt{margin-top: -90rpx;}
.withraw-input{width: 100%;height: 100rpx;}
</style>
